package com.crawler.util;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.alibaba.fastjson.JSON;
import com.crawler.dto.ProxyOneself;
import com.google.common.base.Strings;

/**
 * 调用第三方验证码识别
 * 
 * @ClassName CodeCharge
 * @Description TODO
 * @author TL
 * @date 2016年6月25日 下午6:18:24
 *
 */
public class CodeCharge {
    private static String user = "dtl5582";
    private static String passWD = "tonglin3";

    public static String enterCodeCharge(BufferedImage read,ProxyOneself proxy) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(read, "jpg", baos);
        // 采用超级鹰的在线解析验证码
        String res = null;
        if(proxy==null)
            res =ChaoJiYing.PostPic(user, passWD, "891814", "1006", "4", "0", "0", baos.toByteArray());
        else
            res = ChaoJiYing.PostPic(user, passWD, "891814", "1006", "4", "0", "0", baos.toByteArray(),proxy);
        if (!Strings.isNullOrEmpty(res)) {
            return JSON.parseObject(res).getString("pic_str");
        }

        return null;
    }
}
